﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace Ekton_Manage_Framework.Redis
{
    public class HelpRedisFuncList
    {
        readonly Connection _connection;
        public HelpRedisFuncList(Connection connection)
        {
            _connection = connection;
        }

        //根据key存值
        public void ListSet<T>(string key, List<T> value) where T : class
        {
            foreach (var item in value)
            {
                var data = JsonConvert.SerializeObject(item);
                _connection.db.ListRightPush(key, data);
            }
        }

        //根据key取值
        public List<T> ListGet<T>(string key) where T : class
        {
            var List = _connection.db.ListRange(key);
            List<T> result = new List<T>();
            foreach (var item in List)
            {
                var model = JsonConvert.DeserializeObject<T>(item);
                result.Add(model);
            }
            return result;
        }
    }
}